package com.tsing.cedap.common.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;

@Getter
@Setter
@Accessors(chain = true)
public class PageResult<T> {

    @ApiModelProperty(value = "总条数")
    private long totalCount;

    @ApiModelProperty(value = "总页数")
    private long totalPage;

    @ApiModelProperty(value = "当前页数")
    private long pageNum;

    @ApiModelProperty(value = "每页条数")
    private long pageSize;

    @ApiModelProperty(value = "列表数据")
    private List<T> records;

    public PageResult(IPage<T> page) {
        this.totalCount = page.getTotal();
        this.totalPage = page.getPages();
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.records = page.getRecords();
    }

    public PageResult(IPage<?> page, List<T> records) {
        this.totalCount = page.getTotal();
        this.totalPage = page.getPages();
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.records = records;
    }

    public PageResult(long totalCount, long pageNum, long pageSize, List<T> records) {
        this.totalCount = totalCount;
        this.totalPage = (long) Math.ceil((double) totalCount / pageSize);
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.records = records;
    }

}
